{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "68e6c596",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# 聪明办法学 Python 第二版\n",
    "## Chapter 0 安装 Installation\n",
    "---\n",
    "聪明办法学 Python 教学团队\n",
    "\n",
    "<p>learn.python.the.smart.way@gmail.com</p>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3b9b6a8",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# 安装清单\n",
    "\n",
    "> 所有安装均仅需默认配置即可\n",
    "\n",
    "- Miniconda: <https://docs.conda.io/en/latest/miniconda.html>\n",
    "- Visual Studio Code: <https://code.visualstudio.com/>\n",
    "- Git: <https://git-scm.com/download>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3eb91af",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Miniconda 安装配置"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4585b342",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## 下载 Miniconda\n",
    "\n",
    "Miniconda 下载地址：<https://docs.conda.io/en/latest/miniconda.html>\n",
    "\n",
    "最新版 Miniconda For Windows 下载链接：\n",
    "\n",
    "<https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9358602",
   "metadata": {
    "cell_style": "center",
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Miniconda For Windows 安装配置推荐\n",
    "\n",
    "- Just Me (recommended)\n",
    "- Clear the package cache upon completion"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "963b4fd9",
   "metadata": {
    "cell_style": "split"
   },
   "source": [
    "![](../resources/slides/chap0/pic/miniconda_installation_1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d2168a7",
   "metadata": {
    "cell_style": "split"
   },
   "source": [
    "![](../resources/slides/chap0/pic/miniconda_installation_2.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0312d547",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# 修改 Powershell 执行策略（可选）\n",
    "\n",
    "> 仅 **出现”此系统禁止运行脚本“** 的情况下需要执行本操作\n",
    "\n",
    "![](../resources/slides/chap0/pic/powershell_error.png)\n",
    "\n",
    "在`开始`图标**右键单击**，选择 `Windows PowerShell（管理员）`\n",
    "\n",
    "先输入下面的内容，并回车：\n",
    "```powershell\n",
    "Set-ExecutionPolicy -Scope CurrentUser RemoteSigned\n",
    "```\n",
    "出现如下内容后，输入：`A`，回车：\n",
    "\n",
    "![](../resources/slides/chap0/pic/powershell.png)\n",
    "\n",
    "最后在 **Anaconda Powershell Prompt** 中输入：\n",
    "```bash\n",
    "conda init\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "50b897f3",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# 更换镜像源\n",
    "\n",
    "- Pip 换源\n",
    "- Conda 换源\n",
    "\n",
    "> 加快国内资源下载速度"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ec52c36",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "## 校园网联合镜像站\n",
    "<https://help.mirrors.cernet.edu.cn/>\n",
    "\n",
    "## 阿里巴巴开源镜像站\n",
    "\n",
    "<https://developer.aliyun.com/mirror/>\n",
    "\n",
    "请避免使用代理，不合理的代理设置会导致下载失败"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02919362",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Conda 更换镜像源\n",
    "\n",
    "清华大学开源软件镜像站：<https://help.mirrors.cernet.edu.cn/anaconda/>\n",
    "\n",
    "南方科技大学开源软件镜像站：<https://help.mirrors.cernet.edu.cn/anaconda-extra/>\n",
    "\n",
    "在 **Anaconda Powershell Prompt** 中输入：\n",
    "\n",
    "```bash\n",
    "conda config --set show_channel_urls yes\n",
    "```\n",
    "\n",
    "在镜像站复制文本后，在 **Anaconda Powershell Prompt** 中输入：\n",
    "\n",
    "```bash\n",
    "notepad .condarc # 注意有个小点 \".\" 在 \"condarc\" 的前面\n",
    "```\n",
    "\n",
    "删除原有的所有内容，粘贴刚刚复制的文本，保存文件后关闭\n",
    "\n",
    "最后在 **Anaconda Powershell Prompt** 中输入：\n",
    "\n",
    "```bash\n",
    "conda clean -i # 清除源缓存，以启用镜像源\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0de0a2be",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# PyPI 更换镜像源\n",
    " \n",
    "校园网联合镜像站：<https://help.mirrors.cernet.edu.cn/pypi/>\n",
    "\n",
    "复制文本后，在 **Anaconda Powershell Prompt** 中粘贴运行即可：\n",
    "\n",
    "```bash\n",
    "# 设置 PyPI 镜像源\n",
    "pip config set global.index-url https://mirrors.cernet.edu.cn/pypi/web/simple \n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "054f6cbc",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# 课程环境搭建"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8028b9c",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## 创建与激活 Conda 环境\n",
    "\n",
    "创建 Conda 环境\n",
    "\n",
    "```bash\n",
    "conda create -n p2s python=3.10 # conda 环境创建\n",
    "```\n",
    "\n",
    "其中 ***-n*** 代表创建的环境名称，这里是 ***p2s***，并指定 ***Python 版本为 3.10***\n",
    "\n",
    "激活刚刚创建的 Conda 环境：\n",
    "\n",
    "```bash\n",
    "conda activate p2s # 激活 p2s 环境，不同环境的 Python 包版本不同！\n",
    "```\n",
    "\n",
    "如果需要删除某个 Conda 环境：\n",
    "\n",
    "```bash\n",
    "conda deactivate # 退出该环境\n",
    "conda remove -n p2s --all # 删除整个环境\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0298c33",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Git 下载课程资料\n",
    "\n",
    "Github Repo: <https://github.com/datawhalechina/learn-python-the-smart-way-v2>\n",
    "\n",
    "Gitee Repo: <https://gitee.com/anine09/learn-python-the-smart-way-v2>\n",
    "\n",
    "在 **Anaconda Powershell Prompt** 中，使用 `cd` 命令，进入到指定文件夹，例如：\n",
    "\n",
    "```bash\n",
    "cd C:\\Coding\\ # 注意 cd 与指定文件夹路径之间有个空格\n",
    "```\n",
    "\n",
    "继续输入：\n",
    "\n",
    "```bash\n",
    "git clone https://github.com/datawhalechina/learn-python-the-smart-way-v2 --depth=1 # --depth=1 的作用是只下载最新版本的代码文件\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4cac85fe",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Pip 安装与展示\n",
    "\n",
    "Pip 安装课程所需第三方库\n",
    "\n",
    "```bash\n",
    "pip install jupyter # julia python R\n",
    "```\n",
    "\n",
    "在指定文件夹输入：\n",
    "\n",
    "```bash\n",
    "jupyter lab # 会自动跳转到浏览器\n",
    "```\n",
    "\n",
    "结束学习时使用：\n",
    "\n",
    "```bash\n",
    "Ctrl + C # 关闭 Jupyter Notebook 服务\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "708d553e",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "## VSCode 推荐插件清单\n",
    "\n",
    "- Python\n",
    "- Jupyter\n",
    "- Office Viewer(Markdown Editor)\n",
    "- Black Formatter\n",
    "- Code Runner\n",
    "- Chinese (Simplified) (简体中文) Language Pack for Visual Studio Code"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a9a343d5",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-09T12:23:18.469720Z",
     "start_time": "2023-10-09T12:23:18.466797Z"
    },
    "cell_style": "center",
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# 如果你在本地运行遇到困难\n",
    "\n",
    "我们希望同学们尽可能在本地运行 Python 程序，但是由于种种特殊原因无法运行的，我们提供了一些解决方案"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d011cdf",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# 云端环境的使用\n",
    "- 百度飞桨 AI Studio <https://aistudio.baidu.com/aistudio/index>\n",
    "- Mo（智海平台）<https://momodel.cn/workspace>\n",
    "- 阿里天池 PAI DSW <https://tianchi.aliyun.com/notebook-ai>\n",
    "- Kaggle <https://www.kaggle.com/code>\n",
    "- Google Colab <https://colab.research.google.com/>\n",
    "- Sagemaker Studio Lab <https://studiolab.sagemaker.aws/>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a67f04ed",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "# 用户名包含中文\n",
    "\n",
    "1. 网络上有相关解决方案，请自行尝试\n",
    "2. 可暂时尝试云端环境，但请尽快解决本地问题\n",
    "3. 遇到麻烦请参考课程主页中的 **[答疑交流](https://datawhalechina.github.io/learn-python-the-smart-way-v2/Question/question/)** 版块，并及时向教学团队或助教寻求帮助：<learn.python.the.smart.way@gmail.com>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "66e539c6",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Thank You ;-)\n",
    "Datawhale 聪明办法学 Python 教学团队出品\n",
    "\n",
    "## 关注我们\n",
    "Datawhale 是一个专注 AI 领域的开源组织，以“for the learner，和学习者一起成长”为愿景，构建对学习者最有价值的开源学习社区。关注我们，一起学习成长。\n",
    "<div align=center><img src=\"../resources/datawhale_wechat_qrcode.jpeg\" width = \"250\" height = \"270\"></div>"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Slideshow",
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  },
  "rise": {
   "overlay": "<div class='my-top-right'><img height=40px src='../resources/datawhale_logo.png'/></div><div class='my-top-left'></div>"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
